//
//  WQCMyViewController.m
//  renxinghuan
//
//  Created by 王晓民 on 2018/3/16.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "WQCMyViewController.h"
#import "configuration.h"
#import "WYCHelpController.h"//帮助中心
#import "WYCPersonalCenterController.h"//个人中心
#import "WYCShimingController.h"//实名认证
#import "WYCSetDissController.h"//设置
#import "WQCMyTeamViewController.h"//我的团队
#import "WQCMemberViewController.h"//会员升级
#import "WQCMyEarningViewController.h"//我的收益
#import "WQCMyPoliceViewController.h"//我的报单
#import "WQCAuthViewController.h"//已认证
@interface WQCMyViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)NSArray  *dataSource;
@property(nonatomic,strong)NSArray  *imgtitleSource;
@property(nonatomic,strong)NSArray  *titltSource;
@property(nonatomic,strong)NSArray  *imgSource;
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)UIImageView * headImage;

@end

@implementation WQCMyViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    [self.tableView reloadData];
}
- (void)viewDidLoad {
   
    NSString  *payword = [WYCAccountTool unarchivehavePayPassword];

    NSLog(@"%@",payword);
    [super viewDidLoad];
    [self setupNav];
    self.navigationController.navigationBarHidden = NO;

    _dataSource  = @[@"实名认证",@"我的收益",@"我的团队",@"会员升级"];
    _imgtitleSource = @[@"my_one",@"my_two",@"my_three",@"my_four"];
    _titltSource  = @[@"帮助中心",@"客服热线",@"设置"];
    _imgSource = @[@"my_six",@"my_seven",@"eate"];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, kScreenW, kScreenH) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.sectionFooterHeight = 5;
    self.tableView.sectionHeaderHeight = 5;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}



- (void)setupNav {
    
    [self.navigationController.navigationBar setBarTintColor:wycMain];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationItem.title = @"我的";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark - TableView DataSource Method

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }
    else if(section == 1)
    {
        return 4;
    }
    else
        return 3;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 105;
    }
    else
        return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * strID = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strID forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID];
    }
    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
    
    if(indexPath.section == 0)
    {
        //头像
        _headImage = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 65, 65 )];
        _headImage.image =[UIImage imageNamed:@"图层12"];
        _headImage.userInteractionEnabled = YES;
        _headImage.layer.cornerRadius= _headImage.frame.size.width/2;
        _headImage.layer.masksToBounds = YES;
        [cell.contentView addSubview:_headImage];
        UILabel  *numberLb = [[UILabel alloc]initWithFrame:CGRectMake(_headImage.frame.size.width+_headImage.frame.origin.x+25,30, 120, 20)];
        numberLb.text = [WYCAccountTool unarchiveuserName];
        numberLb.font =[UIFont systemFontOfSize:17];
        numberLb.textColor =[UIColor blackColor];
        numberLb.textAlignment = NSTextAlignmentLeft;
        [cell.contentView addSubview:numberLb];
        
    }
    if (indexPath.section == 1) {
        if (indexPath.row==0) {
            UILabel  *numberLb = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-100, 10, 80, 30)];
            numberLb.font =[UIFont systemFontOfSize:15];
            numberLb.textColor =[UIColor lightGrayColor];
            numberLb.textAlignment = NSTextAlignmentLeft;
            [cell.contentView addSubview:numberLb];
            NSString  *auth = [WYCAccountTool unarchiveisAuth];
            if ([auth isEqualToString:@"1"]) {
                numberLb.text = @"未认证";
            }
           else
           {
               numberLb.text = @"已认证";
               numberLb.textColor = wycMain;

           }
        }
        UILabel *titleLb = [[UILabel alloc]initWithFrame:CGRectMake(45, 10, 80, 30)];
        titleLb.tintColor =[UIColor blackColor];
        titleLb.text =[_dataSource objectAtIndex:indexPath.row];
        
        titleLb.font = [UIFont systemFontOfSize:15];
        [cell.contentView addSubview:titleLb];
        UIImageView *tubiao = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 20, 20)];
        tubiao .image =[UIImage imageNamed:[_imgtitleSource objectAtIndex:indexPath.row]];
        [cell.contentView addSubview:tubiao];
    }
    
    if (indexPath.section == 2) {
        UILabel *titleLb = [[UILabel alloc]initWithFrame:CGRectMake(45, 10, 80, 30)];
        titleLb.tintColor =[UIColor blackColor];
        titleLb.text =[_titltSource objectAtIndex:indexPath.row];
        
        titleLb.font = [UIFont systemFontOfSize:15];
        [cell.contentView addSubview:titleLb];
        UIImageView *tubiao = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 20, 20)];
        tubiao .image =[UIImage imageNamed:[_imgSource objectAtIndex:indexPath.row]];
        [cell.contentView addSubview:tubiao];
        
        if (indexPath.row == 1) {
            UILabel * showlabel = [[UILabel alloc] init];
            showlabel.frame = CGRectMake(ScreenWidth-210, 10, 180, 30);;
            showlabel.font = [UIFont systemFontOfSize:MiddleFont];
            showlabel.textAlignment = NSTextAlignmentRight;
            showlabel.textColor = wycMain;
            showlabel.text = @"400-666-2802";
            [cell.contentView addSubview:showlabel];
         
        }
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 0)
    {
        WYCPersonalCenterController * PersonalCenter = [[WYCPersonalCenterController alloc] init];
        [self.navigationController pushViewController:PersonalCenter animated:NO];
       
    }
    if (indexPath.section == 1) {
        
        
        if (indexPath.row == 0)
        {
          
            NSString  *auth = [WYCAccountTool unarchiveisAuth];
            if ([auth isEqualToString:@"0"]) {
                WQCAuthViewController *auth = [[WQCAuthViewController alloc]init];
                [self.navigationController pushViewController:auth animated:NO];
            }
            else
            {
                // 实名认证
                WYCShimingController * shiming = [[WYCShimingController alloc] init];
                [self.navigationController pushViewController:shiming animated:NO];
            }
        }
        
        else if (indexPath.row == 1)
        {
            NSLog(@"我的收益");
            
            NSString  *auth = [WYCAccountTool unarchiveisAuth];
            if ([auth isEqualToString:@"0"]) {
                WQCMyEarningViewController  *earningView = [[WQCMyEarningViewController alloc]init];
                [self.navigationController pushViewController:earningView animated:YES];
            }
            else
            {
                [SVProgressHUD showImage:nil status:@"您还没有认证，请先实名认证！"];

            }
           
        }
        
        else if (indexPath.row == 2)
        {
            NSLog(@"我的团队");
            NSString  *auth = [WYCAccountTool unarchiveisAuth];
            if ([auth isEqualToString:@"0"]) {
            WQCMyTeamViewController  *teamView = [[WQCMyTeamViewController alloc]init];
            [self.navigationController pushViewController:teamView animated:YES];
            }
            else
            {
                [SVProgressHUD showImage:nil status:@"您还没有认证，请先实名认证！"];

            }
        }
        else  if (indexPath.row == 3)
        {
            NSLog(@"会员升级");
            
            WQCMemberViewController  *memberView = [[WQCMemberViewController alloc]init];
            [self.navigationController pushViewController:memberView animated:YES];
        }
        else  if (indexPath.row == 4)
        {
//            //我的保单
//            WQCMyPoliceViewController *repavView = [[WQCMyPoliceViewController alloc]init];
//            [self.navigationController pushViewController:repavView animated:YES];
        }
    }
    if (indexPath.section == 2) {
        if (indexPath.row == 0) {
           // 帮助中心
            WYCHelpController * shiming = [[WYCHelpController alloc] init];
            [self.navigationController pushViewController:shiming animated:NO];
        }
        else if (indexPath.row == 1)
        {
            UIAlertController *alertController =  [UIAlertController alertControllerWithTitle:@"联系我们" message:@"400-666-2802" preferredStyle:UIAlertControllerStyleAlert];
            
            //添加取消到UIAlertController中
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
            [alertController addAction:cancelAction];
            
            //添加确定到UIAlertController中
            UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"点击了好的按钮");
                NSString *allString = [NSString stringWithFormat:@"tel:400-666-2802"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]];
                
            }];
            
            [alertController addAction:OKAction];
            
            [self presentViewController:alertController animated:YES completion:nil];
        }
        else if (indexPath.row == 2)
        {
           // 设置
            WYCSetDissController  *messageView = [[WYCSetDissController alloc]init];
            [self.navigationController pushViewController:messageView animated:YES];
        }
    }
    
}



@end
